const db = require('../../db')

let queryWeekReport = {
    config: {
        description: '周报查询',
        cors: {
            origin: ['*'],
            additionalHeaders: ['cache-control', 'x-requested-with']
        }
    },
    method: 'post',
    path: '/report/query',
    handler: async (request, h) => {

        let request_body = request.payload

        let stateCode;
        let stateMessage;

        let year = request_body.year
        let week = request_body.week

        let result = {
            data: undefined,
            stateCode: '',
            stateMessage: ''
        }
        let promise = function () {
            return new Promise((resolve, reject) => {
                db.report.find({
                    year: year,
                    week: week
                }, (err, docs) => {
                    if (err) {
                        reject(err)
                    }
                    resolve(docs)
                })
            })
        }

        return await promise()
    }
}

module.exports = queryWeekReport